package com.chb.docter.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.docter.dto.*;
import com.chb.docter.feigns.DeptFeign;
import com.chb.docter.feigns.UserFeign;
import com.chb.docter.mapper.*;
import com.chb.docter.params.RegistrationParam;
import com.chb.docter.params.RegistrationQueryParam;
import com.chb.docter.service.RegistrationService;
import com.hos.entity.his.*;
import com.hos.entity.sys.Dept;
import com.hos.entity.sys.User;
import com.hos.utils.IdGeneratorUtil;
import com.hos.utils.WebUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/13 10:10
 * @description:
 * @modified By:
 * @version:
 */
@Service
@Slf4j
public class RegistrationServiceImpl implements RegistrationService {

    @Resource
    private RegistrationMapper registrationMapper;
    @Resource
    private PatientMapper patientMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Resource
    private CareOrderMapper careOrderMapper;
    @Resource
    private CareHistoryMapper careHistoryMapper;
    @Resource
    private CareOrderItemMapper careOrderItemMapper;
    @Resource
    private UserFeign userFeign;
    @Resource
    private DeptFeign deptFeign;


    @Override
    public String addRegistration(RegistrationParam registrationParam) {


        Registration registration = new Registration();
        // 科室信息
        RegistrationDto registrationDto = registrationParam.getRegistrationDto();
        // 患者信息
        Patient patientDto = registrationParam.getPatientDto();

        // 查询是否患者库中是否有此人
        Boolean flag = selectPatientByIdCard(patientDto);
        if (!flag) {
            patientDto.setPatientId(IdGeneratorUtil.nextId("HZ"));
            patientDto.setCreateTime(new Date());
            patientDto.setIsFinal("0");
            patientDto.setUpdateTime(new Date());
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            patientDto.setPassword(encoder.encode("123456"));
            // 创建该患者
            this.patientMapper.insert(patientDto);
        }

        // 获取挂号流水
        String registrationId = IdGeneratorUtil.nextId("GH");

        // 1.修改科室的挂号编号
        this.deptFeign.updateDeptByDeptId(registrationDto.getDeptId());
        registration.setRegistrationId(registrationId);                             //  设置挂号流水
        registration.setPatientId(patientDto.getPatientId());                       // 设置患者id
        registration.setPatientName(patientDto.getName());                          // 患者姓名
        registration.setDeptId(registrationDto.getDeptId());                        // 设置科室id
        registration.setRegistrationItemId(registrationDto.getRegItemId());         // 设置挂号费用id
        registration.setRegistrationAmount(registrationDto.getRegItemAmount());     // 挂号总金额
        Dept dept = deptFeign.selectDeptByDeptId(registrationDto.getDeptId());
        registration.setRegistrationNumber(dept.getRegNumber());                    // 设置挂号编号
        registration.setRegistrationStatus("0");                                    // 设置挂号状态
        registration.setVisitDate(registrationDto.getVisitDate());                  // 设置就诊日期
        registration.setSchedulingType(registrationDto.getSchedulingType());        // 设置排班类型
        registration.setSubsectionType(registrationDto.getSubsectionType());        // 设置排班时段
        registration.setCreateTime(new Date());                                     // 设置创建时间
        registration.setCreateBy(getUserByToken().getUserName());                   // 设置创建者

        // 2.添加挂号信息
        this.registrationMapper.insert(registration);
        return registrationId;
    }

    public String addRegistration2(RegistrationParam registrationParam) {


        Registration registration = new Registration();
        // 科室信息
        RegistrationDto registrationDto = registrationParam.getRegistrationDto();
        // 患者信息
        Patient patientDto = registrationParam.getPatientDto();

        // 查询是否患者库中是否有此人
        Boolean flag = selectPatientByIdCard(patientDto);
        if (!flag) {
            patientDto.setPatientId(IdGeneratorUtil.nextId("HZ"));
            patientDto.setCreateTime(new Date());
            patientDto.setIsFinal("0");
            patientDto.setUpdateTime(new Date());
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            patientDto.setPassword(encoder.encode("123456"));
            // 创建该患者
            this.patientMapper.insert(patientDto);
        }

        // 获取挂号流水
        String registrationId = IdGeneratorUtil.nextId("GH");

        // 1.修改科室的挂号编号
        this.deptFeign.updateDeptByDeptId(registrationDto.getDeptId());
        registration.setRegistrationId(registrationId);                             //  设置挂号流水
        registration.setPatientId(patientDto.getPatientId());                       // 设置患者id
        registration.setPatientName(patientDto.getName());                          // 患者姓名
        registration.setDeptId(registrationDto.getDeptId());                        // 设置科室id
        registration.setRegistrationItemId(registrationDto.getRegItemId());         // 设置挂号费用id
        registration.setRegistrationAmount(registrationDto.getRegItemAmount());     // 挂号总金额
        Dept dept = deptFeign.selectDeptByDeptId(registrationDto.getDeptId());
        registration.setRegistrationNumber(dept.getRegNumber());                    // 设置挂号编号
        registration.setRegistrationStatus("1");                                    // 设置挂号状态 让其默认收费
        registration.setVisitDate(registrationDto.getVisitDate());                  // 设置就诊日期
        registration.setSchedulingType(registrationDto.getSchedulingType());        // 设置排班类型
        registration.setSubsectionType(registrationDto.getSubsectionType());        // 设置排班时段
        registration.setCreateTime(new Date());                                     // 设置创建时间
        registration.setCreateBy(getPatientToken().getName());                   // 设置创建者

        // 2.添加挂号信息
        this.registrationMapper.insert(registration);
        return registrationId;
    }

    /**
     * 查询患者库中是否有此人
     *
     * @param patientDto 患者参数
     * @return true 代表有此人  false代表没有该人
     */
    private Boolean selectPatientByIdCard(Patient patientDto) {
        LambdaQueryWrapper<Patient> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Patient::getIdCard, patientDto.getIdCard())
                .eq(Patient::getPhone, patientDto.getPhone());
        Patient patient = this.patientMapper.selectOne(wrapper);
        return patient != null;
    }

    @Override
    public void collectFee(String registrationId) {
        LambdaUpdateWrapper<Registration> wrapper = new LambdaUpdateWrapper<>();
        User user = getUserByToken();
        wrapper.eq(Registration::getRegistrationId, registrationId).set(Registration::getRegistrationStatus, 1).set(Registration::getUserId, user.getUserId()).set(Registration::getDoctorName, user.getUserName()).set(Registration::getUpdateTime, new Date());
        registrationMapper.update(wrapper);
    }

    @Override
    public Page<Registration> queryRegistrationForPage(RegistrationQueryParam params) {
        // 设置分页参数
        Page<Registration> page = new Page<>(params.getPageNum(), params.getPageSize());

        LambdaQueryWrapper<Registration> wrapper = new LambdaQueryWrapper<>();
        // 进行条件查询
        if (StringUtils.hasText(params.getPatientName())) {
            wrapper.eq(Registration::getPatientName, params.getPatientName());
        }
        if (Objects.nonNull(params.getDeptId())) {
            wrapper.eq(Registration::getDeptId, params.getDeptId());
        }
        if (StringUtils.hasText(params.getSchedulingType())) {
            wrapper.eq(Registration::getSchedulingType, params.getSchedulingType());
        }
        if (StringUtils.hasText(params.getSubsectionType())) {
            wrapper.eq(Registration::getSubsectionType, params.getSubsectionType());
        }
        if (StringUtils.hasText(params.getVisitDate())) {
            wrapper.eq(Registration::getVisitDate, params.getVisitDate());
        }
        if (StringUtils.hasText(params.getRegStatus())) {
            wrapper.eq(Registration::getRegistrationStatus, params.getRegStatus());
        }

        return this.registrationMapper.selectPage(page, wrapper);
    }

    @Override
    public void doInvalid(String registrationId) {
        LambdaUpdateWrapper<Registration> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Registration::getRegistrationId, registrationId).set(Registration::getRegistrationStatus, 5).set(Registration::getUpdateTime, new Date());
        registrationMapper.update(wrapper);
    }

    @Override
    public void doReturn(String registrationId) {
        LambdaUpdateWrapper<Registration> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Registration::getRegistrationId, registrationId).set(Registration::getRegistrationStatus, 4).set(Registration::getUpdateTime, new Date());
        registrationMapper.update(wrapper);
    }

    @Override
    public List<Registration> queryToBeSeenRegistration(String schedulingType) {
        LambdaQueryWrapper<Registration> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Registration::getSchedulingType, schedulingType);
        wrapper.eq(Registration::getVisitDate, DateUtil.format(new Date(), "yyyy-MM-dd"));
        wrapper.eq(Registration::getDeptId, getUserByToken().getDeptId());
        wrapper.eq(Registration::getRegistrationStatus, 1);
        return registrationMapper.selectList(wrapper);
    }

    @Override
    public List<Registration> queryVisitingRegistration(String schedulingType) {
        LambdaQueryWrapper<Registration> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Registration::getSchedulingType, schedulingType);
        wrapper.eq(Registration::getVisitDate, DateUtil.format(new Date(), "yyyy-MM-dd"));
        wrapper.eq(Registration::getDeptId, getUserByToken().getDeptId());
        wrapper.eq(Registration::getRegistrationStatus, 2);
        return registrationMapper.selectList(wrapper);
    }

    @Override
    public List<Registration> queryVisitCompletedRegistration(String schedulingType) {
        LambdaQueryWrapper<Registration> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Registration::getSchedulingType, schedulingType);
        wrapper.eq(Registration::getVisitDate, DateUtil.format(new Date(), "yyyy-MM-dd"));
        wrapper.eq(Registration::getDeptId, getUserByToken().getDeptId());
        wrapper.eq(Registration::getRegistrationStatus, 3);
        return registrationMapper.selectList(wrapper);
    }

    @Override
    public Integer receivePatient(String registrationId) {
        LambdaUpdateWrapper<Registration> wrapper = new LambdaUpdateWrapper<>();
        User user = getUserByToken();
        wrapper.eq(Registration::getRegistrationId, registrationId)
                // 设置状态为就诊中
                .set(Registration::getRegistrationStatus, 2).set(Registration::getUserId, user.getUserId()).set(Registration::getUpdateTime, new Date()).set(Registration::getDoctorName, user.getUserName());
        return registrationMapper.update(wrapper);
    }

    @Override
    public MyPage<OrderListDto> getRegistrationByStatus(Integer page, Integer pageSize, String orderStatus) {

        // switch (orderStatus) {
        //     case "4":
        //         // 全部订单信息
        //         return getRegistrationByStatusWithSeeDocter("0", null, page, pageSize);
        //     case "0":
        //         // 未支付状态
        //         return getRegistrationByStatusWithSeeDocter("1", null, page, pageSize);
        //     case "2":
        //         // 待付款状态 pendingStatus
        //         return getRegistrationByPendingStatus("2", "0", page, pageSize);
        //     case "3":
        //         // 已完成状态
        //         return getRegistrationByPendingStatus("3", "1", page, pageSize);
        //     case "4":
        //         // 待评价状态:
        //         return getRegistrationByPendingStatus("4", "3", page, pageSize);
        // }
        return getRegistrationByPendingStatus(orderStatus, orderStatus, page, pageSize);
        // return null;
    }

    @Override
    public MyPage<OrderListDto> getRegistrationListAsStatus(Integer page, Integer pageSize, String orderState) {
        Page<Registration> registrationPage = this.getRegistrationListByStatus(orderState, page, pageSize);
        MyPage<OrderListDto> myPage = new MyPage<>();
        // 1.查询挂号列表
        List<Registration> registrationList = registrationPage.getRecords();
        List<OrderListDto> orderListDtoList = new ArrayList<>();
        for (Registration registration : registrationList) {
            OrderListDto orderListDto = new OrderListDto();
            orderListDto.setRegistration(registration);
            // 2.查询医生信息
            User user = this.userFeign.getUserById(registration.getUserId());
            orderListDto.setUser(user);
            // 3.查询科室信息
            Dept dept = this.deptFeign.selectDeptByDeptId(registration.getDeptId());
            orderListDto.setDept(dept);
            orderListDtoList.add(orderListDto);
        }
        myPage.setItems(orderListDtoList);
        myPage.setPage(registrationPage.getCurrent());
        myPage.setCounts(registrationPage.getTotal());
        myPage.setPageSize(registrationPage.getSize());
        myPage.setPages(registrationPage.getPages());
        return myPage;
    }

    @Override
    public String addAppRegistration(AppRegistrationDto appRegistrationDto) {

        RegistrationParam registrationParam = new RegistrationParam();
        Patient patient = getPatientToken();
        RegistrationDto registrationDto = new RegistrationDto();
        registrationDto.setDeptId(appRegistrationDto.getDeptId());
        registrationDto.setRegItemId(1L);
        registrationDto.setRegItemAmount(new BigDecimal(6));
        int year = DateUtil.thisYear();
        String s1 = year + "-" + appRegistrationDto.getVisitDate();

        registrationDto.setVisitDate(s1.substring(0, s1.length() - 2));
        registrationDto.setSchedulingType("1");
        registrationDto.setSubsectionType(appRegistrationDto.getSubsectionType());
        registrationParam.setPatientDto(patient);
        registrationParam.setRegistrationDto(registrationDto);


        String s = addRegistration2(registrationParam);

        return null;
    }

    /**
     * @param returnStatus 返回状态
     * @param orderStatus  支付状态
     * @return java.util.List<com.chb.docter.dto.OrderListDto>
     * @create by: 陈海彬
     * @description: 待付款状态
     * @create time: 2023/12/23 15:19
     */
    private MyPage<OrderListDto> getRegistrationByPendingStatus(String returnStatus, String orderStatus, Integer page, Integer pageSize) {
        List<OrderListDto> orderListDtoList = new ArrayList<>();
        MyPage<OrderListDto> myPage = new MyPage<>();
        // 1.查询当前患者的所有病例信息列表
        Page<CareHistory> careHistoryPage = this.selectCareHistory(page, pageSize);
        List<CareHistory> careHistoryList = careHistoryPage.getRecords();
        if (careHistoryList != null) {
            for (CareHistory careHistory : careHistoryList) {
                // 2.查询当前患者的所有处方类型
                List<CareOrder> careOrderList = this.selectCareOrderByOrderStatus(careHistory.getChId(), orderStatus);
                if (careOrderList != null) {
                    // 3.保存相关返回信息
                    OrderListDto orderListDto = new OrderListDto();
                    orderListDto.setCareHistory(careHistory);
                    orderListDto.setCareOrders(careOrderList);
                    orderListDto.setDept(deptFeign.selectDeptByDeptId(careHistory.getDeptId()));
                    orderListDto.setUser(userFeign.getUserById(careHistory.getUserId()));
                    orderListDto.setTotalMoney(careOrderList.stream().map(CareOrder::getAllAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
                    orderListDto.setTotalNum(this.selectTotalNum(careOrderList));
                    orderListDto.setStatus(returnStatus);
                    orderListDtoList.add(orderListDto);
                }
            }
        }
        // 设置分页返回逻辑
        myPage.setCounts(careHistoryPage.getTotal());
        myPage.setPageSize(careHistoryPage.getSize());
        myPage.setPages(careHistoryPage.getPages());
        myPage.setPage(careHistoryPage.getCurrent());
        myPage.setItems(orderListDtoList);
        return myPage;
    }

    /**
     * @param careOrderList 处方列表
     * @return int
     * @create by: 陈海彬
     * @description: 查询处方总条数
     * @create time: 2023/12/23 15:43
     */
    private int selectTotalNum(List<CareOrder> careOrderList) {
        int total = 0;
        for (CareOrder order : careOrderList) {
            LambdaQueryWrapper<CareOrderItem> careOrderItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
            careOrderItemLambdaQueryWrapper.eq(CareOrderItem::getCoId, order.getCoId());
            List<CareOrderItem> orderItems = this.careOrderItemMapper.selectList(careOrderItemLambdaQueryWrapper);
            int num = orderItems.stream().map(CareOrderItem::getNum).reduce(BigDecimal.ZERO, BigDecimal::add).intValue();
            total += num;
        }
        return total;
    }

    /**
     * @param chId        病例id
     * @param orderStatus 支付状态 子项的状态 0未支付 1已支付 2已退费 3已完成
     * @return java.util.List<com.hos.entity.his.CareOrder>
     * @create by: 陈海彬
     * @description: 查询当前患者的所有处方类型
     * @create time: 2023/12/23 15:29
     */
    private List<CareOrder> selectCareOrderByOrderStatus(String chId, String orderStatus) {
        LambdaQueryWrapper<CareOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CareOrder::getChId, chId);
        List<CareOrder> careOrders = this.careOrderMapper.selectList(wrapper);
        for (CareOrder careOrder : careOrders) {
            careOrder.setCheckStatus(orderStatus);
            // 判断状态
            boolean flag = this.selectCareOrderItemByStatus(careOrder.getCoId(), orderStatus);
            if (flag) {
                return careOrders;
            }
        }
        return null;
    }

    /**
     * @param coId        处方id
     * @param orderStatus 缴费状态 0未支付 1已支付 2已退费 3已完成 5 已取消
     * @return boolean
     * @create by: 陈海彬
     * @description: 查询当前病例子项的缴费情况
     * @create time: 2023/12/23 15:34
     */
    private boolean selectCareOrderItemByStatus(String coId, String orderStatus) {
        LambdaQueryWrapper<CareOrderItem> wrapper = new LambdaQueryWrapper<>();
        if (!"4".equals(orderStatus)) {
            wrapper.eq(CareOrderItem::getStatus, orderStatus);
        }
        wrapper.eq(CareOrderItem::getCoId, coId);
        List<CareOrderItem> items = this.careOrderItemMapper.selectList(wrapper);
        return items.size() > 0;
    }

    /**
     * @return java.util.List<com.hos.entity.his.CareHistory>
     * @create by: 陈海彬
     * @description: 查询当前患者的所有病例信息列表
     * @create time: 2023/12/23 15:25
     */
    private Page<CareHistory> selectCareHistory(Integer page, Integer pageSize) {
        // 1.查询当前登录用户
        Patient patient = getPatientToken();
        Page<CareHistory> careHistoryPage = new Page<>(page, pageSize);
        LambdaQueryWrapper<CareHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CareHistory::getPatientId, patient.getPatientId());
        return this.careHistoryMapper.selectPage(careHistoryPage, wrapper);
    }

    /**
     * @param status      挂号状态
     * @param orderStatus 支付状态
     * @return java.util.List<com.chb.docter.dto.OrderListDto>
     * @create by: 陈海彬
     * @description: 查询订单列表————待就诊状态
     * @create time: 2023/12/21 17:32
     */
    private MyPage<OrderListDto> getRegistrationByStatusWithSeeDocter(String status, String orderStatus, Integer page, Integer pageSize) {
        // 2.进行查询相关信息
        List<OrderListDto> orderListDtoList = new ArrayList<>();
        Page<Registration> listByStatus = this.getRegistrationListByStatus(status, page, pageSize);
        List<Registration> registrationList = listByStatus.getRecords();
        MyPage<OrderListDto> myPage = new MyPage<>();

        log.error(listByStatus.toString() + listByStatus.getTotal());
        for (Registration registration : registrationList) {
            OrderListDto orderListDto = new OrderListDto();
            orderListDto.setRegistration(registration);
            // 3.查询医生信息
            orderListDto.setUser(this.userFeign.getUserById(registration.getUserId()));
            // 4.查询科室信息
            orderListDto.setDept(this.deptFeign.selectDeptByDeptId(registration.getDeptId()));
            // 5.查询病例信息
            if ("3".equals(registration.getRegistrationStatus())) {
                CareHistory careHistory = this.getCareHistoryByRid(registration.getRegistrationId());
                orderListDto.setCareHistory(careHistory);
                // 6.查询处方列表  0未支付 1已支付 2已退费 3已完成
                LambdaQueryWrapper<CareOrder> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(CareOrder::getChId, careHistory.getChId());
                List<CareOrder> orders = this.selectCareOrder(careHistory.getChId());
                // 设置返回列表
                orderListDto.setCareOrders(orders);
                // 7.设置总金额
                orderListDto.setTotalMoney(orders.stream().map(CareOrder::getAllAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
                // 8.设置总条数
                orderListDto.setTotalNum(this.selectTotalNum(orders));
            }
            orderListDtoList.add(orderListDto);
        }
        // 设置分页返回逻辑
        myPage.setCounts(listByStatus.getTotal());
        myPage.setPageSize(listByStatus.getSize());
        myPage.setPages(listByStatus.getPages());
        myPage.setPage(listByStatus.getCurrent());
        myPage.setItems(orderListDtoList);
        return myPage;
    }


    /**
     * @param chId 病例id
     * @return java.util.List<com.hos.entity.his.CareOrder>
     * @create by: 陈海彬
     * @description: 查询订单状态
     * @create time: 2023/12/23 15:11
     */
    private List<CareOrder> selectCareOrder(String chId) {
        LambdaQueryWrapper<CareOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CareOrder::getChId, chId);
        return this.careOrderMapper.selectList(wrapper);
    }


    /**
     * @param regId 挂号id
     * @return com.hos.entity.his.CareHistory
     * @create by: 陈海彬
     * @description: 根据挂号id查询病例信息
     * @create time: 2023/12/21 14:56
     */
    private CareHistory getCareHistoryByRid(String regId) {
        LambdaQueryWrapper<CareHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CareHistory::getRegId, regId);
        return this.careHistoryMapper.selectOne(wrapper);
    }

    /**
     * @param status 挂号状态
     * @return java.util.List<com.hos.entity.his.Registration>
     * @create by: 陈海彬
     * @description: 根据状态查询挂号订单列表
     * @create time: 2023/12/21 14:38
     */
    private Page<Registration> getRegistrationListByStatus(String status, Integer page, Integer pageSize) {
        Patient patient = getPatientToken();
        // 1.分页查询
        Page<Registration> registrationPage = new Page<>(page, pageSize);
        LambdaQueryWrapper<Registration> wrapper = new LambdaQueryWrapper<>();
        if (!"0".equals(status)) {
            wrapper.eq(Registration::getRegistrationStatus, status);
        }
        wrapper.eq(Registration::getPatientId, patient.getPatientId())
                .orderByDesc(Registration::getCreateTime);
        return this.registrationMapper.selectPage(registrationPage, wrapper);
    }

    /**
     * @return com.hos.entity.sys.User
     * @create by: 陈海彬
     * @description: 获取请求用户的信息
     * @create time: 2023/12/12 10:39
     */
    private User getUserByToken() {
        String token = WebUtil.getToken();
        String phone = redisTemplate.opsForValue().get("user:" + token);
        System.out.println("11111111111111111111" + userFeign.selectUserByPhone(phone));
        return userFeign.selectUserByPhone(phone);
    }

    /**
     * @return com.hos.entity.sys.User
     * @create by: 陈海彬
     * @description: 获取请求用户的信息
     * @create time: 2023/12/12 10:39
     */
    private Patient getPatientToken() {
        String token = WebUtil.getToken();
        String phone = redisTemplate.opsForValue().get("user:" + token);
        LambdaQueryWrapper<Patient> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Patient::getPhone, phone);
        Patient patient = this.patientMapper.selectOne(wrapper);
        patient.setPassword("");
        return patient;
    }
}